<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./js/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/vuex/3.2.0/vuex.min.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app">总价：{{prices}}</div>
  </body>
  <script>
    var app = new Vue({
      el: "#app",
      data: {
        package1: [
          {
            name: "iphone7",
            price: 7199,
            count: 2
          },
          {
            name: "iPad",
            price: 2888,
            count: 1
          }
        ],
        package2: [
          {
            name: "apple",
            price: 3,
            count: 5
          },
          {
            name: "bannana",
            price: 2,
            count: 10
          }
        ]
      },
      computed: {
        prices: function () {
          var prices = 0
          for (var i = 0; i < this.package1.length; i++) {
            prices += this.package1[1].price * this.package1[i].count
          }
          for (var i = 0; i < this.package2.length; i++) {
            prices += this.package2[i].price * this.package2[i].count
          }
          return prices
        }
      }
    })
  </script>
  <!-- 计算属性
    每一个计算属性都包含一个getter和一个setter，上面的示例是计算属性的默认用法，只是利用了getter来读取.
--></html>
